<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>用户管理</title>
    <%@ include file="../../include/head.jsp" %>
    <link rel="stylesheet" href="${ctxStatic}/3rd-lib/jquery-ztree/css/zTreeStyle.css">
</head>
<body>
<div class="admin-content">
    <div class="am-g">
        <div class="am-u-sm-3">
            <div class="am-panel am-panel-default">
                <div class="am-panel-hd">机构树</div>
                <div class="am-panel-bd">
                    <div class="am-scrollable-horizontal">
                        <ul id="tree" class="ztree"></ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="am-u-sm-9">
            <div class="am-panel-group" id="accordion">
                <div class="am-panel am-panel-default">
                    <div class="am-panel-hd">
                        <h4 class="am-panel-title" data-am-collapse="{parent: '#accordion', target: '#tab1'}">
                            查询条件
                        </h4>
                    </div>
                    <div id="tab1" class="am-panel-collapse am-collapse am-in">
                        <div class="am-panel-bd">
                            <form id="searchForm" class="am-form-inline" action="${ctx}/user" method="post">
                                <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
                                <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
                                <input type="hidden" name="organizationId" value="${page.entity.organizationId}" />
                                <div class="am-form-group">
                                    <label>登录账号</label>
                                    <input type="text" name="username" value="${page.entity.username}" class="am-form-field">
                                </div>
                                <div class="am-form-group">
                                    <label>姓名</label>
                                    <input type="text" name="name" value="${page.entity.name}" class="am-form-field">
                                </div>
                                <div class="am-form-group">
                                    <label>手机号码</label>
                                    <input type="text" name="mobile" value="${page.entity.mobile}" class="am-form-field">
                                </div>
                                <div class="am-form-group">
                                    <button type="submit" class="am-btn am-btn-success" onclick="initSearchForm()"><i class="am-icon-search"></i> 查询</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="am-panel am-panel-default">
                <div class="am-panel-hd">
                    用户列表
                    <shiro:hasPermission name="sys:user:create">
                    <button type="button" class="am-btn am-btn-primary am-btn-xs iu-right" onclick="openModel('新增','${ctx}/user/create?organizationId=${page.entity.organizationId}')"><span class="am-icon-plus"></span> 新增</button>
                    </shiro:hasPermission>
                </div>
                <div class="am-panel-bd">
                    <div class="am-g">
                        <div class="am-u-sm-12">
                            <table class="am-table am-table-striped am-table-hover table-main">
                                <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>归属机构</th>
                                    <th>账号</th>
                                    <th>姓名</th>
                                    <th>手机号码</th>
                                    <th>是否部门管理员</th>
                                    <th>是否锁定</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach items="${page.list}" var="user" varStatus="status">
                                    <tr>
                                        <td>${status.index+1}</td>
                                        <td>${user.organization.name}</td>
                                        <td>${user.username}</td>
                                        <td>${user.name}</td>
                                        <td>${user.mobile}</td>
                                        <td>${user.isDept?'<span class="am-badge am-badge-danger am-radius">是</span>':'<span class="am-badge am-badge-success am-radius">否</span>'}</td>
                                        <td>${user.locked?'<span class="am-badge am-badge-danger am-radius">是</span>':'<span class="am-badge am-badge-success am-radius">否</span>'}</td>
                                        <td>
                                            <div class="am-btn-toolbar">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    <shiro:hasPermission name="sys:user:update">
                                                        <button class="am-btn am-btn-default am-btn-xs am-text-primary am-hide-sm-only" onclick="openModel('编辑','${ctx}/user/update?id=${user.id}')"><span class="am-icon-pencil"></span> 编辑</button>
                                                    </shiro:hasPermission>
                                                    <shiro:hasPermission name="sys:user:delete">
                                                        <c:if test="${user.id!='1' && user.id!=fnc:getLoginUser().id}">
                                                        <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="iuConfirm('确认要删除该条数据吗？', '${ctx}/user/delete?id=${user.id}&pageNo=${page.pageNo}&pageSize=${page.pageSize}')"><span class="am-icon-trash-o"></span> 删除</button>
                                                        </c:if>
                                                    </shiro:hasPermission>
                                                    <button class="am-btn am-btn-default am-btn-xs am-text-success am-hide-sm-only" onclick="iuConfirm('确认要重置该密码吗？默认密码【123456】', '${ctx}/user/resetPassword?id=${user.id}&pageNo=${page.pageNo}&pageSize=${page.pageSize}')"><span class="am-icon-key"></span> 重置</button>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                        <div class="am-u-sm-12">
                            <%@ include file="../../utils/pagination.jsp" %>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%@ include file="../../include/bottom.jsp"%>
<script src="${ctxStatic}/3rd-lib/jquery-ztree/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var msg = '${msg}';
        if (msg != '') {
            iuMsg(msg);
        }
    });
</script>
<script>
    $(function () {
        var setting = {
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback : {
                onClick : function(event, treeId, treeNode) {
                    location.href = "${ctx}/user?organizationId="+treeNode.id;
                }
            }
        };
        var zNodes =[<c:forEach items="${organizationList}" var="o" varStatus="status">{id:"${o.id}", pId:"${o.parentId}", name:"${o.name}", open:${o.rootNode}}<c:if test="${!status.last}">,</c:if></c:forEach>];
        $(document).ready(function(){
            var ztree = $.fn.zTree.init($("#tree"), setting, zNodes);
            ztree.expandAll(true);
        });
    });
</script>
</body>
</html>